<?php

class Statistics

{
 
              /*function to get the total number of users on the site*/

		function getTotalUsers(){

			$query = "SELECT `id` FROM `users`";
			$result = mysql_query($query);
                        $total = mysql_num_rows($result);
			return $total;			

		}
		
		/*end function*/
		
		/*function to get the total number of files uploaded on the site*/

		function getTotalUploads(){

			$query = "SELECT `id` FROM `uploads`";
			$result = mysql_query($query);
                        $total = mysql_num_rows($result);
			return $total;			

		}
		
		/*end function*/
		
		/*function to get the total number of downloads on the site*/

		function getTotalDownloads(){

			$query = "SELECT `file_id` FROM `downloads`";
			$result = mysql_query($query);
                        $total = mysql_num_rows($result);
			return $total;			

		}
		
		/*end function*/
		
		/*function to get todays total uploads*/
		
		function getTodaysTotalUploads(){
		global $ado;
		$today = date("Y-m-d 00:00:00");		
		$rs = $ado->exec("SELECT count(`id`) as `total` FROM `uploads` WHERE `created_date` >= '$today'");		
		$row = mysql_fetch_assoc($rs); 
		return $row['total'];
	        }
	
	        /*end function*/
	        
	        /*function to get todays total site earnings*/
	        
	        function getAdminsTodaysTotalEarnings(){
			global $ado;
			$today = date("Y:m:d 00:00:00");
			$rs = $ado->exec("SELECT sum( `amount` ) AS `total_earnings` , date( date ) AS `earn_date` FROM `earnings`
						WHERE date >= '$today' group by DAY (`date`)");
			$row = mysql_fetch_assoc($rs);
			return number_format($row['total_earnings'],2);
		}
		/*end function*/
		
		/*function to get todays total site registrations*/
		
		function getTodaysTotalRegistrations(){
		global $ado;
		$today = date("Y-m-d 00:00:00");		
		$rs = $ado->exec("SELECT count(`id`) as `total` FROM `users` WHERE `created_on` >= '$today'");		
		$row = mysql_fetch_assoc($rs); 
		return $row['total'];
	        }
	
	        /*end function*/
	        
	        /*function to get this months earnings*/
	        
	        function getAdminsMonthsEarnings(){
			global $ado;
			
			$start_month_day =  date("Y-m-01 00:00:00");
			$end_month_day =  date("Y-m-31 00:00:00");
			$res = $ado->exec("SELECT sum(`amount`) as `amt` FROM `earnings` WHERE `date` >= '$start_month_day' and `date` <= '$end_month_day' GROUP BY MONTH(`date`) ");
			$row = mysql_fetch_assoc($res);
			if($row['amt'] > 0){
				return number_format($row['amt'],2);	
			}
			else{
				return 0.00;
			}
		}
	        
	        /*end function*/
	        
	        /*function to get this months total site registrations*/
		
		function getMonthlyTotalRegistrations(){
		global $ado;
		$start_month_day =  date("Y-m-01 00:00:00");
		$end_month_day =  date("Y-m-31 00:00:00");		
		$rs = $ado->exec("SELECT count(`id`) as `total` FROM `users` WHERE `created_on` >= '$start_month_day' and `created_on` <= '$end_month_day' GROUP BY MONTH(`created_on`)");		
		$row = mysql_fetch_assoc($rs); 
		return $row['total'];
	        }
	
	        /*end function*/
	        
	        /*function to get this months total downloads*/
		
		function getMonthlyTotalDownloads(){
		global $ado;
		$start_month_day =  date("Y-m-01 00:00:00");
		$end_month_day =  date("Y-m-31 00:00:00");		
		$rs = $ado->exec("SELECT count(`id`) as `total` FROM `downloads` WHERE `date` >= '$start_month_day' and `date` <= '$end_month_day' GROUP BY MONTH(`date`)");		
		$row = mysql_fetch_assoc($rs); 
		if($row['total'] > 0){
				return number_format($row['total']);	
			}
			else{
				return 0;
			}
	        }
	
	        /*end function*/
	        
	        /*function to get this months total uploads*/
		
		function getMonthlyTotalUploads(){
		global $ado;
		$start_month_day =  date("Y-m-01 00:00:00");
		$end_month_day =  date("Y-m-31 00:00:00");		
		$rs = $ado->exec("SELECT count(`id`) as `total` FROM `uploads` WHERE `created_date` >= '$start_month_day' and `created_date` <= '$end_month_day' GROUP BY MONTH(`created_date`)");		
		$row = mysql_fetch_assoc($rs); 
		return $row['total'];
	        }
	
	        /*end function*/


}

global $statistics;

$statistics = new Statistics();

?>